package me.zhengjie.controller;

import io.swagger.annotations.ApiOperation;
import me.zhengjie.common.Result;
import me.zhengjie.dto.AlarmsDto;
import me.zhengjie.dto.MapDto;
import me.zhengjie.dto.Tasks;
import me.zhengjie.entity.TrafficCtlArea;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
public class TsetRestTemplateController {

    @Resource
    private RestTemplate restTemplate;

    @ApiOperation("交管区")
    @PostMapping("/testArea")
    public String test(@RequestBody TrafficCtlArea t1){
        String url = "http://localhost:8087/test1/applyTrafficCtlArea";
        ResponseEntity<String> result = restTemplate.postForEntity(url,t1,String.class);
        String r1 = result.toString();
        System.out.println("result = " + result);
        return r1;
    }

    @ApiOperation("继续/取消")
    @PostMapping("/testTask")
    public Result<Object> testTask(@RequestBody String taskId){
        System.out.println("taskId = " + taskId);
        System.out.println("test 取消/继续任务");
        return Result.ok();
    }
    //发送任务测试
    @PostMapping("/test3")
    public Result<Object> test3(@RequestBody Tasks tasks){
        System.out.println("tasks = " + tasks);
        System.out.println("santTask test");
        return Result.ok();
    }

    //地图
    @GetMapping("/getMapInfo")
    public Result<MapDto> getMapInfo(@RequestParam String mapId){
        MapDto mapDto = new MapDto();
        mapDto.setId(Integer.valueOf(mapId));
        mapDto.setY(1);
        mapDto.setX(2);
        mapDto.setName("a002");

        return Result.ok(mapDto);
    }

    //agv异常
    @GetMapping("/rpc/getAlarms")
    public Result<AlarmsDto> getAlarms(){
        AlarmsDto alarmsDto = new AlarmsDto();
        alarmsDto.setCode("400");
        alarmsDto.setAlarm("it is wrong!!");
        return Result.ok(alarmsDto);
    }
}
